package edu.unika.aifb.graphindex;


import java.util.Set;

import joptsimple.OptionParser;
import joptsimple.OptionSet;

import org.apache.log4j.Logger;

import edu.unika.aifb.graphindex.index.IndexDirectory;
import edu.unika.aifb.graphindex.index.IndexReader;
import edu.unika.aifb.graphindex.query.KeywordQuery;
import edu.unika.aifb.graphindex.searcher.keyword.evaluation.Row;
import edu.unika.aifb.graphindex.searcher.keyword.evaluation.TopKQueryEvaluator;

public class Demo {
	//program arguments: -o C:\rane\workspace3.6.1\DBGraphIndex\indexes\dbindex
	//vm arguments: -Xms1024m -Xmx1024m
	private static final Logger log = Logger.getLogger(Demo.class);
	
	public static void main(String[] args) throws Exception {
		OptionParser op = new OptionParser();
		op.accepts("o", "output directory").withRequiredArg().ofType(String.class).describedAs("directory");
		
		OptionSet os = op.parse(args);
		
		if (!os.has("o")) {
			op.printHelpOn(System.out);
			return;
		}

		String directory = (String)os.valueOf("o");
		
		IndexReader ir = new IndexReader(new IndexDirectory(directory));
		KeywordQuery[] kqs = new KeywordQuery[]{new KeywordQuery("q1", "einstein special relativity")};
		TopKQueryEvaluator topKQueryEvaluator = new TopKQueryEvaluator(ir);
		
		for(KeywordQuery kq : kqs){
			System.out.println(kq.getQuery());
			System.out.println();
			Set<Row> rows =  topKQueryEvaluator.evaluate(kq, 3, 10);
			System.out.println("HIER " + rows.size());
			int i = 1;
			for(Row row : rows){
				System.out.println((i++) + ". "+row);
			}
			System.out.println();
			System.out.println();
		}
		ir.close();
	}
}
